import axios from 'axios'
import {
  Message
} from 'element-ui'
import {
  getToken,
  removeToken
} from '@/utils/auth'

const service = axios.create({
  baseURL: process.env.BASE_API, // api的base_url
  timeout: 300000 // 请求超时时间
})
// request拦截器
service.interceptors.request.use(config => {
  // Do something before request is sent
  if (getToken() != null)
    config.headers['Authorization'] = getToken() // 让每个请求携带token--['Authorization']为自定义key 请根据实际情况自行修改

  return config;
}, error => {
  // Do something with request error
  return Promise.reject(error);
});
service.interceptors.response.use(
  response => {
    return response;
  },

  error => {

    removeToken()
    return Promise.reject(error)
  })


export default service
